package luafrontend.interpreter;

import java.io.PrintStream;
import java.util.Stack;

public class InterpreterState {
	private final Stack<InterpreterFunction> callStack = new Stack<InterpreterFunction>();
	private FunctionCallback functionCallback;
	
	public void enterFunction(InterpreterFunction f) {
		callStack.push(f);
	}
	
	public void leaveFunction() {
		callStack.pop();
	}
	
	public InterpreterFunction getCurrentFunction() {
		return callStack.peek();
	}
	
	public void printCallStack(PrintStream stream, String prefix) {
		for (int i = callStack.size() - 1; i >= 0; --i) {
			stream.print(prefix);
			stream.println(callStack.get(i).getDebugName());
		}
	}
	
	public FunctionCallback getFunctionCallback() {
		return functionCallback;
	}
	
	public void setFunctionCallback(FunctionCallback callback) {
		functionCallback = callback;
	}
}
